package main

import "fmt"

func maxPoints(points [][]int) int {
	if len(points) < 2 {
		return len(points)
	}
	abs := func(x int) int {
		if x > 0 {
			return x
		}
		return -x
	}
	count := 0
	// 对points按照x坐标排序
	for i := 0; i < len(points) - 1; i ++ {
		for j := i + 1; j > 0; j -- {
			if points[j][0] > points[j - 1][0] {
				break
			}
			points[j], points[j - 1] = points[j - 1], points[j]
		}
	}
	fmt.Println(points)
	left, right := 0, 1
	for right < len(points) {
		if abs(points[left][0] - points[right][0]) == 1 {
			if abs(points[left][1] - points[right][1]) == 1 {  // 在一条线上
				count += 1
				left ++
				right ++
			}else {  // 不在一条直线上
				left = right
				right ++
			}
		}else {
			left ++
			right ++
		}
	}


	return count
}

func main()  {
	fmt.Println(maxPoints([][]int{{1,1}, {3,2}, {5,3}, {4,1}, {2,3}, {1,4}}))
}
